package com.hyts.infodb.boot.base;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;

import com.hyts.infodb.error.ApplicationException;

/**
 * @title BootServerApplication.java
 * @package com.hyts.infodb
 * @description TODO
 * @author LiBo/Alex
 * @version V1.0
 */
//@FunctionalInterface
public interface BootServerApplication {


    int order();

    /**
     * @param args
     * @param parentApplicationContext
     * @return
     * @exception
     */
    boolean boot(String[] args,ConfigurableApplicationContext parentApplicationContext);

    /**
     * @exception
     */
    default ConfigurableApplicationContext buildServer(Class<?> application,ConfigurableApplicationContext configurationApplicationContext,String[] args) {
        try {
            ConfigurableApplicationContext serverApplicationContext =
                    new SpringApplicationBuilder(application).web(WebApplicationType.SERVLET)
                    .parent(configurationApplicationContext).bannerMode(Banner.Mode.OFF).run(args);
/*            AnnotationConfigServletWebServerApplicationContext springApplication = (AnnotationConfigServletWebServerApplicationContext) serverApplicationContext;
            springApplication.set*/
            return serverApplicationContext;
        } catch (Exception e) {
            throw new ApplicationException(e);
        }
    }

}
